package com.dayaokeji.rhythmschoolstudent.client.home.course.task;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.ApiConstantKt;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUrlModel;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUtils;


/**
 * Created by Gorden on 2018/3/23.
 */

public class FilesAdapter extends BaseQuickAdapter<FilesAdapter.FileBean,BaseViewHolder> {

    private static boolean isShowDel = false;

    public FilesAdapter() {
        super(R.layout.item_add_img, null);
    }

    public static void setIsShowDel(boolean isShowDel) {
        FilesAdapter.isShowDel = isShowDel;
    }

    @Override
    protected void convert(BaseViewHolder helper, FileBean item) {
        helper.addOnClickListener(R.id.iv_del_img);
        ImageView imageView = helper.getView(R.id.iv_add_file_img);
        ImageView delImage = helper.getView(R.id.iv_del_img);
        if (!TextUtils.isEmpty(item.getFilePath())) {
            GlideUtils.with(mContext).load("file://"+item.getFilePath()).into(imageView);
        }
        if (item.getRemoteImgResId() != -1){
            if (item.getRemoteImgResId() != null) {
                GlideUtils.with(mContext).load(new GlideUrlModel(ApiConstantKt.getRemoteImageUrl()+item.getRemoteImgResId())).into(imageView);
            }
        }

        delImage.setVisibility(isShowDel ? View.VISIBLE: View.GONE);
        if (item.getFileRes() != null) {
            delImage.setVisibility(View.INVISIBLE);
            imageView.setImageResource(item.getFileRes());
        }

    }

    public static class FileBean{
        private String filePath;
        private Integer fileRes;
        private Integer remoteImgResId = -1;

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public Integer getFileRes() {
            return fileRes;
        }

        public void setFileRes(Integer fileRes) {
            this.fileRes = fileRes;
        }

        public Integer getRemoteImgResId() {
            return remoteImgResId == null ? -1 : remoteImgResId;
        }

        public void setRemoteImgResId(Integer remoteImgResId) {
            this.remoteImgResId = remoteImgResId;
        }
    }
}
